"""
质量检查--监理检查
"""
import logging

import pytest
from Config.Base import Base
from playwright.sync_api import Page, expect, Playwright
from Config.config import *
from Config.URL import *
import allure, os
from Config.Base import Base
from Config.Tool import tool

@pytest.mark.业务系统
@pytest.mark.质量管理
def test_case(playwright : Playwright) -> None:
    # headless=False
    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    page.goto(url + url_login)
    allure.step("登录")
    page.get_by_placeholder("请输入用户名").fill('jianli1')
    page.get_by_placeholder("请输入密码").fill('HBuat2025&2025')
    page.get_by_role("button", name="登 录").click()
    expect(page.locator("#tags-view-container")).to_contain_text("项目首页")
    allure.step("跳转监理检查")
    page.goto(url+url_jianlijiancha)
    allure.step("新建")
    page.get_by_role("button", name=" 新建").click()
    allure.step("选择标段")
    page.get_by_label("请选择标段").get_by_text(bd_zhihuigu).click()
    page.get_by_role("button", name="确 定").click()
    allure.step("选择检查类型-日常检查")
    page.get_by_placeholder("请选择检查类型").click()
    page.locator("ul").filter(has_text=re.compile(r"^日常检查$")).locator("span").click()
    allure.step("增加问题")
    page.get_by_role("button", name="增加问题").click()
    page.get_by_role("row",
                     name="起重机、行车等安装检验不符合技术标准 单元工程质量检验与评定 严重 管理员 2023-09-25 19:23").locator(
        "label span").nth(1).click()
    page.get_by_role("button", name="确 定").click()
    allure.step("输入问题描述")
    page.get_by_placeholder("请输入问题描述").fill("监理检查-问题描述")
    allure.step("上传图片")
    page.locator("div").filter(has_text=re.compile(r"^问题照片加载失败$")).locator("i").click()
    with page.expect_file_chooser() as fc_info:
        page.locator(".normal > .el-upload").click()
    file_chooser = fc_info.value
    file_chooser.set_files(test_datas_dir+"\图片.jpg")
    allure.step("等待上传完成")
    page.wait_for_timeout(2000)
    page.get_by_placeholder("请输入整改要求").fill("监理检查-整改要求")

    # 测试结果截图
    filename = os.path.join(test_screenshot_dir, f"{'质量管理-监理检查页面'}.png")
    page.screenshot(path=filename)
    allure.attach.file(source=filename, name='质量管理-监理检查页面',
                       attachment_type=allure.attachment_type.PNG)

    allure.step("发起流程")
    page.get_by_role("button", name="发起流程").click()
    expect(page.get_by_role("alert")).to_contain_text("流程发起成功")


    allure.step("监理单位审批")
    page.locator("#tags-view-container").get_by_text("项目首页").click()
    page.get_by_role("row", name="1 【质量检查-监理检查】").locator("span").nth(1).click()
    page.get_by_placeholder("请输入整改完成情况").fill("监理检查-整改完成情况")
    with page.expect_file_chooser() as fc_info:
        page.locator("div:nth-child(5) > .el-form-item > .el-form-item__content > .pit-upload-listCard > .normal > .el-upload").click()
    file_chooser = fc_info.value
    file_chooser.set_files(test_datas_dir+"\图片.jpg")
    allure.step("等待上传完成")
    page.wait_for_timeout(2000)
    # 测试结果截图
    filename = os.path.join(test_screenshot_dir, f"{'质量管理-监理检查-整改完成情况'}.png")
    page.screenshot(path=filename)
    allure.attach.file(source=filename, name='质量管理-监理检查-整改完成情况',
                       attachment_type=allure.attachment_type.PNG)
    page.get_by_placeholder("请输入签署密码").fill(password_flow)
    page.get_by_placeholder("请选择签章").click()
    page.get_by_text("监理单位项目1部-企业公章").click()
    page.get_by_role("button", name="通 过").click()
    expect(page.locator("body")).to_contain_text("审批通过")
    # 断言
    #expect(page.get_by_text('新建成功！')).to_be_visible()



    context.close()
    SetupTeardown.close()


